#include "synsock_api.h"

extern UINT32	evcode_base;

#define EV_SOCK_NOTIFY		evcode_base + 1


socket_f *				socket = NULL;
socket_connect_f *		socket_connect = NULL;
socket_write_f *		socket_write = NULL;
socket_read_f *			socket_read = NULL;
socket_bind_f *			socket_bind = NULL;
socket_close_f *		socket_close = NULL;
socket_delete_f *		socket_delete = NULL;
socket_activity_f *		socket_activity = NULL;

void netapi_init( UINT32 * params )
{
	socket = (socket_f *)(params[0]);
	socket_connect = (socket_connect_f *)(params[1]);
	socket_write = (socket_write_f *)(params[2]);
	socket_read = (socket_read_f *)(params[3]);
	socket_bind = (socket_bind_f *)(params[4]);
	socket_close = (socket_close_f *)(params[5]);
	socket_delete = (socket_delete_f *)(params[6]);
	socket_activity = (socket_activity_f *)(params[7]);
}

// net API
int net_new( int type )
{
	if ( socket == NULL )
		return -1;
	return socket( type, EV_SOCK_NOTIFY );
}
int net_connect( int sock, const char * host, int port )
{
	return socket_connect(sock, host, port);
}
size_t net_write( int sock, const void * buf, size_t size )
{
	return socket_write(sock, buf, size);
}
size_t net_read( int sock, void * buf, size_t size )
{
	return socket_read(sock, buf, size);
}
int net_bind( int sock, int port )
{
	return socket_bind( sock, port );
}
int net_close( int sock )
{
	return socket_close( sock );
}
int net_kill( int sock )
{
	return socket_delete(sock);
}
int net_ping( int sock )
{
	return socket_activity(sock);
}



